package br.com.sgi.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

@Entity
@Table(name = "AUTHORITIES")
@NamedQueries({

	@NamedQuery(name = "buscarAuthoritiesPorUsername", 
			query = "SELECT a FROM Authorities a " +
					" WHERE a.sistema.coSeqSistema =:coSistema " +
					" AND a.username.username = :username"
			)	
			
})
public class  Authorities implements Serializable  {

	
	private static final long serialVersionUID = 1L;


	@Id
	@Column(name="co_seq_authorities")
	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "co_seq_authorities_seqauthorities")  
	@SequenceGenerator(name = "co_seq_authorities_seqauthorities", sequenceName = "SGI.seq_authorities") 
	private Long coSeqAuthorities;
	
	
	@ManyToOne
	@JoinColumn(name="USERNAME", unique=true)
	private Users username;

	@NotNull
	@Size(min = 1, max = 50)
	private String authority;
	
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="CO_SISTEMA")
	private Sistema sistema;


	public Users getUsername() {
		return username;
	}

	public void setUsername(Users username) {
		this.username = username;
	}

	public String getAuthority() {
		return authority;
	}

	public void setAuthority(String authority) {
		this.authority = authority;
	}

	public Long getCoSeqAuthorities() {
		return coSeqAuthorities;
	}

	public void setCoSeqAuthorities(Long coSeqAuthorities) {
		this.coSeqAuthorities = coSeqAuthorities;
	}
	

	public Sistema getSistema() {
		return sistema;
	}

	public void setSistema(Sistema sistema) {
		this.sistema = sistema;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((coSeqAuthorities == null) ? 0 : coSeqAuthorities.hashCode());
		return result;
	}

	
}
